<template>
  <uni-popup ref="infoDialog" background-color="#fff">
    <view class="popup-contents">
      <div class="company-img">
        <div class="top-img">
          <image src="/static/user-tabbar-icons/logo.jpeg" />
        </div>
        <div class="bot-name">
          中恩智能助手
        </div>
      </div>
      <div class="top-text">
        <text class="text">
          是否接收审批结果通知
        </text>
      </div>
      <div class="bot-button">
        <button type="default" plain="true" @click="close">
          拒绝
        </button>
        <button type="primary" @click="dialogConfirm">
          允许
        </button>
      </div>
    </view>
  </uni-popup>
</template>

<script>
import { subMsg } from '@/apis/office'
export default {
  props: {
    infoId: {
      type: String,
    },
  },
  data() {
    return {
      type: 'bottom',
    }
  },
  methods: {
    open() {
      this.$refs.infoDialog.open(this.type)
    },
    close() {
      this.$refs.infoDialog.close()
    },
    dialogConfirm() {
      const that = this
      uni.requestSubscribeMessage({
        tmplIds: ['uy7a9Rmx-7KphknIxl-PRCnr5psyjF8TjJevtuQOt44'],
        async success(res) {
          if (res['uy7a9Rmx-7KphknIxl-PRCnr5psyjF8TjJevtuQOt44'] === 'accept') {
            // 用户接受了订阅
            await subMsg(that.infoId)
            // 在这里处理用户接受的逻辑
          }
        },
        fail(res) {
          uni.showToast({
            icon: 'none',
            title: '授权失败',
          })
        },
      })
      that.$refs.infoDialog.close()
    },
  },
}
</script>

<style lang="scss" scoped>
.dialog-info{
	background: #fff;
	width: 200px;
	height: 100px;
	border-radius: 5px;
	div{
		width: 100%;
		height: 50%;
	}
	div:nth-child(1){
		display: flex;
		justify-content: center;
		align-items: center;
	}
	div:nth-child(2){
		text-align: center;
	}
}
</style>
<style lang="scss">
	.popup-contents{
		height:150px;
		background-color: #fff;
		.company-img{
			height: 20%;
			padding-left: 10px;
			padding-top: 10px;
			display: flex;
			.top-img{
				width: 20px;
				height: 20px;
				image{
					width:100%;
					height:100%;
				}
			}
			.bot-name{
				font-weight: 600;
				padding-left: 10px;
			}
		}
		.top-text{
			height: 50%;
			display:flex;
			font-size: 16px;
			align-items:center;
			justify-content: center;
			font-weight: 600;
		}
		.bot-button{
			height: 30%;
			display:flex;
			align-items: flex-end;
			button{
				font-size: 15px;
				width: 30%;
				height: 80%;
				display: flex;
				align-items: center;
				justify-content: center;
			}
			button:nth-child(1){
				background: #efeeee;
				color: #1aad19;
				border: none;
			}
		}
	}
</style>
